<?php

/**
 * Mobile and area query.
 */

$start_time = microtime(true);

include('MobileAreaDb.class.php');

$mobile = '13210000000';

if (empty($mobile)) {
    die('Please input your mobile');
}

if(!preg_match("/^1[3456789]\d{9}$/", $mobile)){
    die('Please input right mobile');
}

$db_name = 'mobile' . substr($mobile , 0, 3);
$mobile_db = new MobileAreaDb($db_name);

if (!$mobile_db->has_file()) {
    die('There is no info about the mobile');
}

$prefix = intval(substr($mobile , 3, 4));
$info = $mobile_db->findByPk($prefix);
if (!$info) {
    die('There is no result about the mobile');
}

if ($info['areaId']) {        
    $location_db = new MobileAreaDb('youbian');
    $info['areaInfo'] = $location_db->findByPk($info['areaId']);
}

$end_time = microtime(true);
echo ($end_time - $start_time) * 1000 . " ms\r\n";

var_dump($info);
